#This script is designed to combine sprites from multiple sources into one image
#Designed for a directory structure.
#Also make sure your sources are consistent in dimensions
import os
import pygame
pygame.init()

def load_dir(dir): return [pygame.image.load(os.path.join(dir,f)) for f in os.listdir(dir)]

sources={}
while True:
	src=input("source directory>")
	if 'cancel'==src.lower() and len(sources.keys())>1:break
	sources[src]=load_dir(src)

while True:
	try:os.chdir(input("output directory>"));break
	except:continue

imgs=sorted([ sources[key] for key in sources.keys()],key=lambda l:len(l))
assert len(imgs)>1
assert len(imgs[0])>1
spr_size=[imgs[0][0].get_width()*len(imgs),imgs[-1][-1].get_height()]
num_sprites=len(imgs[0])
for i in range(0,num_sprites):
	exp=pygame.Surface(spr_size,pygame.SRCALPHA)
	exp.fill((255,0,255))
	pos=[0,0]
	for spr in [img[i] for img in imgs]:
		exp.blit(spr,pos)
		pos[0]+=spr.get_width()
	pygame.image.save(exp,"{:0>4}.png".format(i))
